import Poster from "./poster";
(function test() {
  const poster = new Poster({
    view: {
      width: 250,
      height: 400,
    },
    source: [],
    elements: [
      {
        type: "IMAGE",
        src: "https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/f8296434ec5896b809e56304063668a4.jpg",
        x: 0,
        y: 0,
        width: 250,
        height: 400,
      },
      {
        type: "TEXT",
        content: "aaaaaaaaaaaaaa",
        fontSize: 24,
        algin: "center",
        x: 75,
        y: 30,
        width: 100,
        height: 70,
        color: "rgba(125,125,125,1)",
        editable: true,
      },
      {
        type: "TEXT",
        content: "BBB\n换行",
        fontSize: 24,
        algin: "left",
        x: 0,
        y: 0,
        width: 100,
        height: 70,
        color: "rgba(125,125,125,1)",
      },
      {
        type: "TEXT",
        content: "CCC\n换行",
        fontSize: 24,
        algin: "right",
        x: 150,
        y: 0,
        width: 100,
        height: 70,
        color: "rgba(125,125,125,1)",
        editable: true,
      },
      {
        type: "IMAGE",
        src: "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=4247246815,1422026774&fm=26&gp=0.jpg",
        x: 25,
        y: 325,
        width: 50,
        height: 50,
        editable: true,
      },
    ],
  });

  poster.toDataUrl().then((dataUrl) => {
    const img = new Image();
    img.src = dataUrl;

    document.body.appendChild(img);
  });

  const editor = poster.toEditor("root", {
    onFocus: (style, index) => {
      switch (style.type) {
        case "IMAGE":
          {
            const src = window.prompt("输入图片地址");
            if (src !== null) {
              editor.setContent(src, index);
            }
          }
          break;
        case "TEXT":
          {
            const content = window.prompt("输入文本内容");
            if (content !== null) {
              editor.setContent(content, index);
            }
          }
          break;
      }
      poster.toDataUrl().then((dataUrl) => {
        const img = new Image();
        img.src = dataUrl;

        document.body.appendChild(img);
      });
    },
  });
})();
